import java.net.*;
import java.net.InetAddress;
import java.io.IOException;
import java.util.Vector;
import java.util.Iterator;

/**
 * 
 * @author Jeroen
 *
 */
public class Server extends ServerSocket implements Runnable{
	public boolean isTrue = true;
	private Vector<Service> services;
	private String documentRoot;
	
	public Server(InetAddress host, int port, String path) throws IOException 
	{
		super(port, 50, host);
		services = new Vector<Service>();
		documentRoot = path;
		
		
	}
	public void run()
	{	
		try
		{
			System.out.println("Accepting: ");
			while(isTrue){
				Socket client = this.accept();
				System.out.println("= Accepting client: "+ client+" =");
				Service s = new Service(client, documentRoot);
				s.start();
				services.add(s);
				
			}
		}
		catch(IOException ie)
		{
			System.out.println("\n== Closing server ==\n");
			for (Iterator<Service> i = services.iterator(); i.hasNext();){
				Service s = i.next();
				s.close();
			}
		}
		
	}
}
